/******************************************************************************
 * FileName:    gwin_board.h
 * Desc:        板载
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

#ifndef _GWIN_BOARD_H_
#define _GWIN_BOARD_H_


/*-------------------------- Includes ---------------------------------------*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

#include "rtl876x_nvic.h"
#include "rtl876x_rcc.h"
#include "rtl876x_gpio.h"
#include "rtl876x_rtc.h"
#include "rtl876x_tim.h"
#include "rtl876x_uart.h"
#include "rtl876x_pinmux.h"
#include "platform_os.h"
#include "trace.h"
#include "mible_log.h"
#include "mi_config.h"

#include <os_msg.h>
#include <os_task.h>
#include <gap.h>

#include "gwin_misc_api.h"
#include "gwin_product_info.h"


/*-------------------------- Macro Definitions ------------------------------*/
#define GWIN_DEBUG_EN                           ( 0 )

#define GWIN_PIN_WAKEUP_EXTERN                  P2_4
#define GWIN_PIN_WAKEUP_EXTERN_VALID_LEVEL      1
#define TIMER_WAKEUP_EXTERN_PERIOD              ( 5000 )                // 5ms有效脉宽
#define TIMER_WAKEUP_EXTERN_NUM                 TIM5
#define TIMER_WAKEUP_EXTERN_IRQN                TIMER5_IRQ
#define TIMER_WAKEUP_EXTERN_HANDLER             Timer5_Handler

#define GINW_UARTx                              1
#define GWIN_UART_HANDLER                       UART1_Handler
#define GWIN_PIN_UART_TX                        P2_6
#define GWIN_PIN_UART_RX                        P2_5
#define GWIN_UART_MAX_LEN                       ( 256 + 16 )

#define GWIN_PIN_PWR_MSC                        P0_6
#define GWIN_PIN_IIC_SCL_MSC                    P0_5
#define GWIN_PIN_IIC_SDA_MSC                    P0_4

#define _GWIN_DEV_DEBUG(fmt, ...)               DBG_DIRECT(fmt, ##__VA_ARGS__)
#define GWIN_DEV_DEBUG(fmt, ...)                MI_LOG_ERROR("GWIN_DEBUG [%s %d] "fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__)


/*-------------------------- Type Declarations ------------------------------*/
typedef int8_t (*gwin_uart_recv_callback_t) (uint8_t *data, uint16_t len);
typedef void (*gwin_low_pwr_wakeup_callback_t) (uint8_t pin);


/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
void gwin_board_init(void);

void gwin_wakeup_extern_set_state(uint8_t on);
void gwin_uart_interrupt_set_callback(gwin_uart_recv_callback_t uart_recv_data_parse);
void gwin_uart_send(const uint8_t *data, uint16_t len);
void gwin_low_pwr_set_callback(gwin_low_pwr_wakeup_callback_t recv_callback);
void gwin_low_pwr_set(uint8_t en);
uint8_t gwin_low_pwr_check(void);
void gwin_low_pwr_enter(void);
void gwin_low_pwr_exit(void);
void gwin_low_pwr_interrupt_handler(void);
void gwin_ble_adv_send(const uint8_t *data, uint16_t len);
void gwin_ble_adv_stop(void);
uint8_t gwin_ble_adv_send_with_timems(const uint8_t *data, uint8_t len, uint32_t timems);

void gwin_dynamic_qr_code_init(void);
void gwin_dynamic_qr_code_set(void);
#endif // _GWIN_BOARD_H_


/*-------------------------- END OF FILE ------------------------------------*/

